package com.yidu.hbatsft.service.impl;

import com.github.pagehelper.PageHelper;
import com.yidu.hbatsft.dao.AtsRivalMapper;
import com.yidu.hbatsft.dao.AtsRivalResultMapper;
import com.yidu.hbatsft.domain.AtsRival;
import com.yidu.hbatsft.domain.AtsRivalResult;
import com.yidu.hbatsft.service.RivalResultSerice;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class RivalResultSericeimpl implements RivalResultSerice{


    /**
     * 对手成绩
     */
    @Resource
    AtsRivalResultMapper atsRivalResultMapper;

    /**
     * 对手信息
     */
    @Resource
    AtsRivalMapper atsRivalMapper;


    @Override
    public int deleteByPrimaryKey(Integer resultId) {
        return 0;
    }



    /**
     * 新增和修改
     * @param record
     * @return
     */
    @Override
    public int insert(AtsRivalResult record) {

        Date date = new Date();
        //:hh:mm:ss
        SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy-MM-dd");

        record.setIsva(1);
        record.setSort(1);
        record.setCreater("admin");

        record.setCreatTime(dateFormat.format(date));

        if (StringUtils.isEmpty(record.getResultId())) {


            AtsRival atsRival = atsRivalMapper.findbyid(record.getRivId());

            record.setRivName(atsRival.getRivName());

            record.setRivId(atsRival.getRivId());

            return atsRivalResultMapper.insert(record);



        }else{

            AtsRival atsRival = atsRivalMapper.findbyid(record.getRivId());

            record.setRivName(atsRival.getRivName());

            record.setRivId(atsRival.getRivId());

            return atsRivalResultMapper.updateByPrimaryKey(record);
        }

    }


    @Override
    public int insertSelective(AtsRivalResult record) {
        return 0;
    }

    @Override
    public AtsRivalResult selectByPrimaryKey(Integer resultId) {
        return null;
    }

    @Override
    public int updateByPrimaryKeySelective(AtsRivalResult record) {
        return 0;
    }

    @Override
    public int updateByPrimaryKey(AtsRivalResult record) {
        return 0;
    }

    @Override
    public void updates(int id) {

    }


    /**
     * 删除
     * @param id
     */
    @Override
    public void delete(Integer id) {
        atsRivalResultMapper.updatese(id);
    }

    /**
     * 批量删除
     * @param ids
     */
    @Override
    public void deleteAll(String ids) {

        String temp[] = ids.split(",");
        for (int i = 0; i < temp.length; i++) {
            String id = temp[i];
            if (StringUtils.isEmpty(id)) {
                continue;
            }
            delete(Integer.valueOf(id));
        }

    }

    @Override
    public AtsRivalResult findbyid(Integer id) {



        AtsRivalResult  as = atsRivalResultMapper.findbyid(id);


        return as;





    }

    @Override
    public List<AtsRivalResult> findAll2() {
        return null;
    }


    /**
     * 查询
     * @param map
     * @return
     */
    @Override
    public List<AtsRivalResult> selectAll(Map<String, Object> map,Integer id) {
        return null;
    }



    /**
     * 查询全部
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public List<AtsRivalResult> findAll(Integer pageNum, Integer pageSize,Integer id) {

        PageHelper.startPage(pageNum,pageSize);

        List<AtsRivalResult> list =  atsRivalResultMapper.findAll(id);


        return list;
    }


    /**
     * 查询总行数
     * @return
     */
    @Override
    public int count() {
        return atsRivalResultMapper.count();
    }



    @Override
    public int counts(AtsRivalResult atsRivalResult) {
        return atsRivalResultMapper.counts(atsRivalResult);
    }

    @Override
    public List<AtsRivalResult> findAlls(AtsRivalResult atsRivalResult) {

        return atsRivalResultMapper.findAlls(atsRivalResult);
    }
}
